<?php
/**
 * 集合場所地図選択メニューコンポーネントクラスモジュール
 */
require_once dirname(__FILE__) . '/../Components.php';
require_once APPLICATION_PATH . '/models/Place/Controller.php';
require_once 'Smarty/Components/select.php';

/**
 * 集合場所地図選択メニューコンポーネントクラス
 * Enter description here ...
 * @author shinichi
 *
 */
class Components_MapSelect extends Components
{
	/** テンプレートファイル名 */
	const TEMPLATE_NAME = 'MapSelect.tpl';

	/** リクエストキー：地図ＩＤ */
	const KEY_MAPID = 'mapid';

	/** 会場データセット */
	protected $_objDatasetPlace;
	/** 会場辞書 */
	protected $_aryPlaceDic;
	/** 地図選択メニューオプション */
	protected $_aryMapSelectOptions;

	/** コンポーネント：セレクト */
	protected $objMapSelectMenu;

	public function __construct($sCompileId)
	{
		parent::__construct(dirname(__FILE__), $sCompileId);

		$this->_initMapMenu();
	}

	public function fetch()
	{
		$this->view->SelectMenu = $this->_objMapSelectMenu->fetch();
		$sHtml = parent::fetch(self::TEMPLATE_NAME);
		return $sHtml;
	}

	/**
	 * 地図選択メニュー初期化
	 * Enter description here ...
	 */
	protected function _initMapMenu()
	{
		$this->_objDatasetPlace = new Models_Place_Xml_Controller();
		$this->_createPlaceDictionary();
		$this->_createMapSelectOptions();

		$this->_objMapSelectMenu
		= new Smarty_Components_Select(
				$this->_sCompileDir,
				$this->_sCompileId,
				self::KEY_MAPID,
				$this->_aryMapSelectOptions);
	}

	/**
	 * 会場辞書作成
	 * Enter description here ...
	 * @return multitype:unknown
	 */
	protected function _createPlaceDictionary()
	{
		$aryResult = array();
		$aryDatasetPlace = $this->_objDatasetPlace->getArrayData();
		foreach ( $aryDatasetPlace['LIST'] as $PlaceInfo ) {
			$aryResult[$PlaceInfo['ID']] = $PlaceInfo;
		}
		$this->_aryPlaceDic = $aryResult;
		$this->view->aryDatasetPlace = $aryDatasetPlace['LIST'];
		return $aryResult;
	}

	/**
	 * 地図選択メニューオプション作成
	 * Enter description here ...
	 */
	protected function _createMapSelectOptions()
	{
		$this->_aryMapSelectOptions = array();
		foreach( $this->_aryPlaceDic as $KEY=>$PlaceInfo ) {
			$this->_aryMapSelectOptions[$KEY] = $PlaceInfo['NAME'];
		}
	}
}